package de.herberlin.colormatcher;

import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Applet launcher.
 * 
 * @author hans joachim herbertz
 * created 14.07.2003
 */
public class AsApplet extends Applet {

	public void init() {
		String version = System.getProperty("java.version");
		setLayout(new BorderLayout());

		try {
			float vers = new Float(version.substring(0, 3)).floatValue();
			System.out.println(version + " detected.");
			if (vers < 1.3f) {
				versionMessage(version);
				return;
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();

		}
		try {
			add(
			new Colormatcher(),
				BorderLayout.CENTER);

		} catch (Exception e1) {
			e1.printStackTrace();
		}
	}

	private void versionMessage(String version) {
		String text =
			"Your java runtime is out of date.\n"
				+ "Please download the latest java version "
				+ "from http://java.sun.com";
		text =
			System.getProperty("java.vendor")
				+ " "
				+ System.getProperty("java.version")
				+ " detected.\n\n"
				+ text;
		TextArea area = new TextArea(text);
		area.setEditable(false);
		add(area, BorderLayout.CENTER);
		Button button = new Button("download");
		Panel p = new Panel();
		p.add(button);
		add(p, BorderLayout.SOUTH);
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					getAppletContext().showDocument(
						new URL("http://java.sun.com"),
						"_blank");
				} catch (MalformedURLException eme) {
					eme.printStackTrace();
				}
			}
		});

	}
}
